﻿using FC.ERP.TMom.Infrastructure.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FC.ERP.TMom.Infrastructure.Implementes
{
    public class BaseRepository<T>: IBaseRepository<T> where T : class
    {
        private readonly ErpDbContext _db;
        public BaseRepository(ErpDbContext db)
        {
            _db = db;
        }

        public IQueryable<T> GetAll()
        {
            return _db.Set<T>().AsQueryable();
        }

       public async Task<int> Add(T entity)
        {
            await _db.Set<T>().AddAsync(entity);
            return await _db.SaveChangesAsync();
        }

        public async Task<int> Update(T entity)
        {
            _db.Set<T>().Update(entity);
            return await _db.SaveChangesAsync();
        }
    }
}
